package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.common.PageResult;
import com.itheima.ydd.entity.YddUser;
import com.itheima.ydd.mapper.YddUserMapper;
import com.itheima.ydd.service.YddUserService;
import org.springframework.stereotype.Service;

@Service
public class YddUserServiceImpl extends ServiceImpl<YddUserMapper, YddUser> implements YddUserService {
    /**
     * 分页条件查询
     * @param sex
     * @param username
     * @param mobile
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageResult getList(Integer sex, String username, String mobile, Long page, Long limit) {
        //构造分页构造器对象
        Page<YddUser> pageInfo = new Page<>(page,limit);
        //条件构造器
        LambdaQueryWrapper<YddUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(sex != null, YddUser::getSex, sex)
                .like(username != null, YddUser::getUsername, username)
                .like(mobile != null, YddUser::getMobile, mobile);
        this.page(pageInfo, queryWrapper);
        return PageResult.init(pageInfo.getTotal(),page,limit,pageInfo.getRecords());
    }
}
